package com.example.demo.service.impl;

import com.example.demo.domain.Role;
import com.example.demo.domain.User;
import com.example.demo.mapper.RoleMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.query.RoleQuery;
import com.example.demo.query.UserQuery;
import com.example.demo.service.IRoleService;
import com.example.demo.service.IUserService;
import com.example.demo.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements IRoleService{
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> listRoleByUserId(Long userid) {
        return roleMapper.listRoleByUserId(userid);
    }


    @Override
    public PageList listpage(RoleQuery userQuery) {
        PageList pageList  = new PageList();
        //查询总的条数
        Long total = roleMapper.queryTotal(userQuery);
        List<User> users = roleMapper.queryData(userQuery);
        pageList.setTotal(total);
        pageList.setRows(users);
        //分页查询的数据
        return pageList;
    }

    @Override
    public void saveRole(Role role) {
        roleMapper.saveRole(role);
    }

    @Override
    public void editSaveRole(Role role) {
        roleMapper.editSaveRole(role);
    }

    @Override
    public void deleteRole(Long id) {
        roleMapper.deleteRole(id);
    }
}
